package com.freesun.shop.entity;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;


public class Integer2Long extends JsonDeserializer<List<Object>>{

	@Override
	public List<Object> deserialize(JsonParser p, DeserializationContext ctxt)
			throws IOException, JsonProcessingException {
		// 读取的是当前字段的值 [1,2]
		TreeNode readTree = p.getCodec().readTree(p);

		List<Object> longObject = null ;
		if(readTree.isArray()) {
			ArrayNode arrayNode = (ArrayNode)readTree;
			longObject = new ArrayList<Object>(arrayNode.size());
			for (JsonNode jsonNode : arrayNode) {
				String value = jsonNode.asText();
				longObject.add(Long.valueOf(value));
			}
		}
		return longObject;
	}

}
